package com.hmall.pay.interceptor;

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Fegin拦截器
 *
 * @Author mr.wu
 * @Date 2025-11-12 15:37
 */
@Component
public class FeignInterceptor {


    @Bean
    public RequestInterceptor requestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate template) {
                Long userId = UserContext.getUser();

                if(userId!=null) {
                    //在请求头中添加用户id
                    template.header("user-info", userId.toString());
                }
            }
        };
    }
}
